package object;

/**
 * 演示Object经常被重写的equals()方法
 */
public class EqualsDemo {
    public static void main(String[] args) {
        /**
        Point p1=new Point(100,200);
        Point p2=new Point(100,200);
        System.out.println(p1==p2);//false,比较的是地址
        //因为Point类重写了equals（）方法
        //所以此处调用的重写之后的equals，比较的是属性是否相同
        System.out.println(p1.equals(p2));
         **/
        String a1=new String("hello");
        String a2=new String("hello");
        System.out.println(a1.equals(a2));


        StringBuilder builder1=new StringBuilder("hello");
        StringBuilder builder2=new StringBuilder("hello");
        System.out.println(builder1.equals(builder2));
//a1与builder1类型不同，所以equals()一定是false
        System.out.println(a1.equals(builder1));//false
    }


}
